<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['product']) && ($_SESSION['product'] <= 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 		= $objRequest->getParams();
$intAction 		= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$arrProductId 	= isset($arrParams['pproductid']) ? $arrParams['pproductid'] : null;
$strBackUrl		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
$intError  		= 0;
if($intAction && $arrProductId) {
	$objProduct	= new Product();
	switch ($intAction) {
		case 1: // active		
			if(isset($_SESSION['product']) && ($_SESSION['product']&1<<5) != 0) {	
				foreach($arrProductId as $row) {					
					$intError  = $objProduct->updateStatus($AppUI->id,$row,1,32);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 2: // delete
			if(isset($_SESSION['product']) && ($_SESSION['product']&1<<3) != 0) {				
				foreach($arrProductId as $row) {					
					$objProduct->updateStatus($AppUI->id,$row,2,8);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 3: // suspend
			if(isset($_SESSION['product']) && ($_SESSION['product']&1<<4) != 0) {				
				foreach($arrProductId as $row) {
					$objProduct->updateStatus($AppUI->id,$row,0,16);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 4: // delete database
			if(isset($_SESSION['product']) && ($_SESSION['product']&1<<3) != 0 && $AppUI->type > 1) {
				foreach($arrProductId as $row) {					
					$objProduct->delete($AppUI->id,$row);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 5:
		case 6:
			if(isset($_SESSION['product']) && ($_SESSION['product']&1<<5) != 0) {	
				foreach($arrProductId as $row) {					
					$intError  = $objProduct->updateHot($AppUI->id,$row);
				}
			}
			else {
				$intError = 1;
			}
			break;
	}
} else {
	$intError = 1;
}
if($intError == 0) {
	Vfriend_Function::setMsg($arrMessage[$intAction]);
} else {
	Vfriend_Function::setError($arrError[$intError]);	
}
Vfriend_Function::redirect($strBackUrl);
?>